package org.gdtc.storefront.service.impl;

import org.gdtc.storefront.entity.Notice;
import org.gdtc.storefront.mapper.NoticeMapper;
import org.gdtc.storefront.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@RestController
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return noticeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(@RequestBody Notice notice) {
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        try {
            // 将String类型转换为Date类型
            Date dataTimes = sim.parse(notice.getCreatetime());

            notice.setCureateDate(dataTimes);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return noticeMapper.insert(notice);
    }

    @Override
    public Notice selectByPrimaryKey(Integer id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Notice> selectAll() {
        return noticeMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(@RequestBody Notice record) {
        return noticeMapper.updateByPrimaryKey(record);
    }

}

